package com.gxa.modules.app.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.app.dto.MyCouponDto;
import com.gxa.modules.app.dto.MyCouponQueryDto;
import com.gxa.modules.app.service.CouponStoreService;
import com.gxa.modules.sys.entity.Coupon;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "卡劵商城接口")
@RestController
@Slf4j
public class CouponStoreController {
    
    @Autowired
    private CouponStoreService couponStoreService;

    @ApiOperation(value="卡劵商城查询接口")
    @GetMapping("couponStore/list")
    public Result queryCoupon(){
        try {
            List<Coupon> coupons = this.couponStoreService.queryAllCoupon();
            Map map = new HashMap();
            map.put("coupon",coupons);
            return new Result().ok(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error("查询失败");
        }
    }

    @ApiOperation(value="我的卡劵接口")
    @PostMapping("/myCoupon/list")
    public Result queryMyCouponById(@RequestBody MyCouponDto myCouponDto){
        try {
            Date nowDate = new Date(System.currentTimeMillis());
            myCouponDto.setNowDate(nowDate);
            List<MyCouponQueryDto> myCouponList = this.couponStoreService.queryMyCouponById(myCouponDto);
            return new Result().ok(myCouponList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error("查询失败");
        }
    }


}
